package myAsm;

import java.util.Map;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.objectweb.asm.MethodVisitor;


@Entity
@DiscriminatorValue("INSN_VAR")
public class MyVarInsnNode extends MyAbstractInsnNode {

	 /**
     * The operand of this instruction. This operand is the index of a local
     * variable.
     */
	@Column(name="VARINSN_VAR")
    private int var;

	public int getVar() {
		return var;
	}

	public void setVar(int var) {
		this.var = var;
	}

	public MyVarInsnNode() {
		super(-1);
    }
	
    /**
     * Constructs a new {@link VarInsnNode}.
     * 
     * @param opcode the opcode of the local variable instruction to be
     *        constructed. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD,
     *        ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
     * @param var the operand of the instruction to be constructed. This operand
     *        is the index of a local variable.
     */
    public MyVarInsnNode(final int opcode, final int var) {
        super(opcode);
        this.var = var;
    }

    /**
     * Sets the opcode of this instruction.
     * 
     * @param opcode the new instruction opcode. This opcode must be ILOAD,
     *        LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE
     *        or RET.
     */
    public void setOpcode(final int opcode) {
        this.opcode = opcode;
    }

    public int getType() {
        return VAR_INSN;
    }

    public void accept(final MethodVisitor mv) {
        mv.visitVarInsn(opcode, var);
    }

    public MyAbstractInsnNode clone(final Map labels) {
        return new MyVarInsnNode(opcode, var);
    }
}